import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { getResponse, parseParameters, createPagination } from 'utils/utils';
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { fetchPointList as _fetchPointList, deletePoint as _deletePoint, refreshPoint as _refreshPoint, fetchRuleList as _fetchRuleList, fetchRuleDetail as _fetchRuleDetail, deleteRule as _deleteRule, createRule as _createRule, updateRule as _updateRule, fetchRangeList as _fetchRangeList, createRange as _createRange, updateRange as _updateRange, deleteRange as _deleteRange, fetchRangeDetail as _fetchRangeDetail, fetchPointListToRange as _fetchPointListToRange, fetchRuleListToRange as _fetchRuleListToRange, deletePointToRange as _deletePointToRange, deleteRuleToRange as _deleteRuleToRange, applyRules as _applyRules } from "../services/customizeService";
export default {
  namespace: 'customize',
  state: {
    pointList: [],
    pointPagination: {},
    ruleList: [],
    rulePagination: {},
    rangeList: [],
    rangePagination: {},
    rangeDetail: {},
    pointToRangeList: [],
    // 范围对应的切入点数据列表
    ruleToRangeList: [] // 范围对应的规则数据列表

  },
  effects: {
    // 个性化切入
    fetchPointList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchPointList(_ref, _ref2) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchPointList$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.t0 = getResponse;
              _context.next = 5;
              return call(_fetchPointList, parseParameters(payload));

            case 5:
              _context.t1 = _context.sent;
              result = (0, _context.t0)(_context.t1);

              if (!result) {
                _context.next = 10;
                break;
              }

              _context.next = 10;
              return put({
                type: 'customize/updateState',
                payload: {
                  pointList: result.content,
                  pointPagination: createPagination(result)
                }
              });

            case 10:
              return _context.abrupt("return", result);

            case 11:
            case "end":
              return _context.stop();
          }
        }
      }, fetchPointList);
    }),
    deletePoint: /*#__PURE__*/_regeneratorRuntime.mark(function deletePoint(_ref3, _ref4) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deletePoint$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.t0 = getResponse;
              _context2.next = 5;
              return call(_deletePoint, payload);

            case 5:
              _context2.t1 = _context2.sent;
              res = (0, _context2.t0)(_context2.t1);
              return _context2.abrupt("return", res);

            case 8:
            case "end":
              return _context2.stop();
          }
        }
      }, deletePoint);
    }),
    refreshPoint: /*#__PURE__*/_regeneratorRuntime.mark(function refreshPoint(_ref5, _ref6) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function refreshPoint$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;
              _context3.t0 = getResponse;
              _context3.next = 5;
              return call(_refreshPoint, payload);

            case 5:
              _context3.t1 = _context3.sent;
              res = (0, _context3.t0)(_context3.t1);
              return _context3.abrupt("return", res);

            case 8:
            case "end":
              return _context3.stop();
          }
        }
      }, refreshPoint);
    }),
    // 个性化规则
    fetchRuleList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchRuleList(_ref7, _ref8) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchRuleList$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call, put = _ref8.put;
              _context4.t0 = getResponse;
              _context4.next = 5;
              return call(_fetchRuleList, parseParameters(payload));

            case 5:
              _context4.t1 = _context4.sent;
              result = (0, _context4.t0)(_context4.t1);

              if (!result) {
                _context4.next = 10;
                break;
              }

              _context4.next = 10;
              return put({
                type: 'customize/updateState',
                payload: {
                  ruleList: result.content,
                  rulePagination: createPagination(result)
                }
              });

            case 10:
              return _context4.abrupt("return", result);

            case 11:
            case "end":
              return _context4.stop();
          }
        }
      }, fetchRuleList);
    }),
    fetchRuleDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchRuleDetail(_ref9, _ref10) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchRuleDetail$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call, put = _ref10.put;
              _context5.t0 = getResponse;
              _context5.next = 5;
              return call(_fetchRuleDetail, payload);

            case 5:
              _context5.t1 = _context5.sent;
              result = (0, _context5.t0)(_context5.t1);

              if (!result) {
                _context5.next = 10;
                break;
              }

              _context5.next = 10;
              return put({
                type: 'customize/updateState',
                payload: {
                  ruleDetail: result
                }
              });

            case 10:
              return _context5.abrupt("return", result);

            case 11:
            case "end":
              return _context5.stop();
          }
        }
      }, fetchRuleDetail);
    }),
    fetchValueListToRule: /*#__PURE__*/_regeneratorRuntime.mark(function fetchValueListToRule(_, _ref11) {
      var call, put, result;
      return _regeneratorRuntime.wrap(function fetchValueListToRule$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              call = _ref11.call, put = _ref11.put;
              _context6.t0 = getResponse;
              _context6.next = 4;
              return call(queryMapIdpValue, {
                typeCodeList: 'CPFM.CUSTOMIZE_RULE_TYPE',
                rulePositionList: 'CPFM.CUSTOMIZE_RULE_POSITION'
              });

            case 4:
              _context6.t1 = _context6.sent;
              result = (0, _context6.t0)(_context6.t1);

              if (!result) {
                _context6.next = 9;
                break;
              }

              _context6.next = 9;
              return put({
                type: 'customize/updateState',
                payload: {
                  typeCodeList: result.typeCodeList,
                  rulePositionList: result.rulePositionList
                }
              });

            case 9:
              return _context6.abrupt("return", result);

            case 10:
            case "end":
              return _context6.stop();
          }
        }
      }, fetchValueListToRule);
    }),
    createRule: /*#__PURE__*/_regeneratorRuntime.mark(function createRule(_ref12, _ref13) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createRule$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              call = _ref13.call;
              _context7.t0 = getResponse;
              _context7.next = 5;
              return call(_createRule, payload);

            case 5:
              _context7.t1 = _context7.sent;
              res = (0, _context7.t0)(_context7.t1);
              return _context7.abrupt("return", res);

            case 8:
            case "end":
              return _context7.stop();
          }
        }
      }, createRule);
    }),
    updateRule: /*#__PURE__*/_regeneratorRuntime.mark(function updateRule(_ref14, _ref15) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateRule$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref14.payload;
              call = _ref15.call;
              _context8.t0 = getResponse;
              _context8.next = 5;
              return call(_updateRule, payload);

            case 5:
              _context8.t1 = _context8.sent;
              res = (0, _context8.t0)(_context8.t1);
              return _context8.abrupt("return", res);

            case 8:
            case "end":
              return _context8.stop();
          }
        }
      }, updateRule);
    }),
    deleteRule: /*#__PURE__*/_regeneratorRuntime.mark(function deleteRule(_ref16, _ref17) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteRule$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref16.payload;
              call = _ref17.call;
              _context9.t0 = getResponse;
              _context9.next = 5;
              return call(_deleteRule, payload);

            case 5:
              _context9.t1 = _context9.sent;
              res = (0, _context9.t0)(_context9.t1);
              return _context9.abrupt("return", res);

            case 8:
            case "end":
              return _context9.stop();
          }
        }
      }, deleteRule);
    }),
    // 个性化范围
    fetchRangeList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchRangeList(_ref18, _ref19) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchRangeList$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref18.payload;
              call = _ref19.call, put = _ref19.put;
              _context10.t0 = getResponse;
              _context10.next = 5;
              return call(_fetchRangeList, parseParameters(payload));

            case 5:
              _context10.t1 = _context10.sent;
              result = (0, _context10.t0)(_context10.t1);

              if (!result) {
                _context10.next = 10;
                break;
              }

              _context10.next = 10;
              return put({
                type: 'customize/updateState',
                payload: {
                  rangeList: result.content,
                  rangePagination: createPagination(result)
                }
              });

            case 10:
              return _context10.abrupt("return", result);

            case 11:
            case "end":
              return _context10.stop();
          }
        }
      }, fetchRangeList);
    }),
    fetchRangeDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchRangeDetail(_ref20, _ref21) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchRangeDetail$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref20.payload;
              call = _ref21.call, put = _ref21.put;
              _context11.t0 = getResponse;
              _context11.next = 5;
              return call(_fetchRangeDetail, payload);

            case 5:
              _context11.t1 = _context11.sent;
              result = (0, _context11.t0)(_context11.t1);

              if (!result) {
                _context11.next = 10;
                break;
              }

              _context11.next = 10;
              return put({
                type: 'customize/updateState',
                payload: {
                  rangeDetail: result
                }
              });

            case 10:
              return _context11.abrupt("return", result);

            case 11:
            case "end":
              return _context11.stop();
          }
        }
      }, fetchRangeDetail);
    }),
    fetchPointListToRange: /*#__PURE__*/_regeneratorRuntime.mark(function fetchPointListToRange(_ref22, _ref23) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchPointListToRange$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              payload = _ref22.payload;
              call = _ref23.call, put = _ref23.put;
              _context12.t0 = getResponse;
              _context12.next = 5;
              return call(_fetchPointListToRange, payload);

            case 5:
              _context12.t1 = _context12.sent;
              result = (0, _context12.t0)(_context12.t1);

              if (!result) {
                _context12.next = 10;
                break;
              }

              _context12.next = 10;
              return put({
                type: 'customize/updateState',
                payload: {
                  pointToRangeList: result
                }
              });

            case 10:
              return _context12.abrupt("return", result);

            case 11:
            case "end":
              return _context12.stop();
          }
        }
      }, fetchPointListToRange);
    }),
    fetchRuleListToRange: /*#__PURE__*/_regeneratorRuntime.mark(function fetchRuleListToRange(_ref24, _ref25) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchRuleListToRange$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              payload = _ref24.payload;
              call = _ref25.call, put = _ref25.put;
              _context13.t0 = getResponse;
              _context13.next = 5;
              return call(_fetchRuleListToRange, payload);

            case 5:
              _context13.t1 = _context13.sent;
              result = (0, _context13.t0)(_context13.t1);

              if (!result) {
                _context13.next = 10;
                break;
              }

              _context13.next = 10;
              return put({
                type: 'customize/updateState',
                payload: {
                  ruleToRangeList: result
                }
              });

            case 10:
              return _context13.abrupt("return", result);

            case 11:
            case "end":
              return _context13.stop();
          }
        }
      }, fetchRuleListToRange);
    }),
    deletePointToRange: /*#__PURE__*/_regeneratorRuntime.mark(function deletePointToRange(_ref26, _ref27) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deletePointToRange$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              payload = _ref26.payload;
              call = _ref27.call;
              _context14.t0 = getResponse;
              _context14.next = 5;
              return call(_deletePointToRange, payload);

            case 5:
              _context14.t1 = _context14.sent;
              res = (0, _context14.t0)(_context14.t1);
              return _context14.abrupt("return", res);

            case 8:
            case "end":
              return _context14.stop();
          }
        }
      }, deletePointToRange);
    }),
    deleteRuleToRange: /*#__PURE__*/_regeneratorRuntime.mark(function deleteRuleToRange(_ref28, _ref29) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteRuleToRange$(_context15) {
        while (1) {
          switch (_context15.prev = _context15.next) {
            case 0:
              payload = _ref28.payload;
              call = _ref29.call;
              _context15.t0 = getResponse;
              _context15.next = 5;
              return call(_deleteRuleToRange, payload);

            case 5:
              _context15.t1 = _context15.sent;
              res = (0, _context15.t0)(_context15.t1);
              return _context15.abrupt("return", res);

            case 8:
            case "end":
              return _context15.stop();
          }
        }
      }, deleteRuleToRange);
    }),
    createRange: /*#__PURE__*/_regeneratorRuntime.mark(function createRange(_ref30, _ref31) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createRange$(_context16) {
        while (1) {
          switch (_context16.prev = _context16.next) {
            case 0:
              payload = _ref30.payload;
              call = _ref31.call;
              _context16.t0 = getResponse;
              _context16.next = 5;
              return call(_createRange, payload);

            case 5:
              _context16.t1 = _context16.sent;
              res = (0, _context16.t0)(_context16.t1);
              return _context16.abrupt("return", res);

            case 8:
            case "end":
              return _context16.stop();
          }
        }
      }, createRange);
    }),
    updateRange: /*#__PURE__*/_regeneratorRuntime.mark(function updateRange(_ref32, _ref33) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateRange$(_context17) {
        while (1) {
          switch (_context17.prev = _context17.next) {
            case 0:
              payload = _ref32.payload;
              call = _ref33.call;
              _context17.t0 = getResponse;
              _context17.next = 5;
              return call(_updateRange, payload);

            case 5:
              _context17.t1 = _context17.sent;
              res = (0, _context17.t0)(_context17.t1);
              return _context17.abrupt("return", res);

            case 8:
            case "end":
              return _context17.stop();
          }
        }
      }, updateRange);
    }),
    deleteRange: /*#__PURE__*/_regeneratorRuntime.mark(function deleteRange(_ref34, _ref35) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteRange$(_context18) {
        while (1) {
          switch (_context18.prev = _context18.next) {
            case 0:
              payload = _ref34.payload;
              call = _ref35.call;
              _context18.t0 = getResponse;
              _context18.next = 5;
              return call(_deleteRange, payload);

            case 5:
              _context18.t1 = _context18.sent;
              res = (0, _context18.t0)(_context18.t1);
              return _context18.abrupt("return", res);

            case 8:
            case "end":
              return _context18.stop();
          }
        }
      }, deleteRange);
    }),
    applyRules: /*#__PURE__*/_regeneratorRuntime.mark(function applyRules(_ref36, _ref37) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function applyRules$(_context19) {
        while (1) {
          switch (_context19.prev = _context19.next) {
            case 0:
              payload = _ref36.payload;
              call = _ref37.call;
              _context19.t0 = getResponse;
              _context19.next = 5;
              return call(_applyRules, payload);

            case 5:
              _context19.t1 = _context19.sent;
              res = (0, _context19.t0)(_context19.t1);
              return _context19.abrupt("return", res);

            case 8:
            case "end":
              return _context19.stop();
          }
        }
      }, applyRules);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref38) {
      var payload = _ref38.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};